SlideShare a Scribd company logo
1 of 5
Develop a game, with two gamers. Games rules made up
themselfs. For example can take game “guess number”. Prepare
at least 5 functions in program. Develop a game, with two
gamers. Games rules made up themselfs. For example can take
game “guess number”. Prepare at least 5 functions in program.
Develop a game, with two gamers. Games rules made up
themselfs. For example can take game “guess number”. Prepare
at least 5 functions in program. with function description and
java programming code (using eclipse)
Solution
import java.util.Scanner; /** * Tic-Tac-Toe: Two-player
console, non-graphics, non-OO version. * All
variables/methods are declared as static (belong to the class) *
in the non-OO version. */ public class TTTConsoleNonOO2P {
// Name-constants to represent the seeds and cell contents
public static final int EMPTY = 0; public static final int
CROSS = 1; public static final int NOUGHT = 2; // Name-
constants to represent the various states of the game public
static final int PLAYING = 0; public static final int DRAW =
1; public static final int CROSS_WON = 2; public static
final int NOUGHT_WON = 3; // The game board and the
game status public static final int ROWS = 3, COLS = 3; //
number of rows and columns public static int[][] board = new
int[ROWS][COLS]; // game board in 2D array
// containing (EMPTY, CROSS, NOUGHT) public static int
currentState; // the current state of the game
// (PLAYING, DRAW, CROSS_WON, NOUGHT_WON)
public static int currentPlayer; // the current player (CROSS or
NOUGHT) public static int currntRow, currentCol; // current
seed's row and column public static Scanner in = new
Scanner(System.in); // the input Scanner /** The entry main
method (the program starts here) */ public static void
main(String[] args) { // Initialize the game-board and
current status initGame(); // Play the game once do
{ playerMove(currentPlayer); // update currentRow and
currentCol updateGame(currentPlayer, currntRow,
currentCol); // update currentState printBoard(); //
Print message if game-over if (currentState ==
CROSS_WON) { System.out.println( "'X' won!
Bye!"); } else if (currentState == NOUGHT_WON) {
System.out.println("'O' won! Bye!"); } else if
(currentState == DRAW) { System.out.println("It's a
Draw! Bye!"); } // Switch player
currentPlayer = (currentPlayer == CROSS) ? NOUGHT :
CROSS; } while (currentState == PLAYING); // repeat if
not game-over } /** Initialize the game-board contents and
the current states */ public static void initGame() { for
(int row = 0; row < ROWS; ++row) { for (int col = 0; col
< COLS; ++col) { board[row][col] = EMPTY; // all
cells empty } } currentState = PLAYING; // ready
to play currentPlayer = CROSS; // cross plays first }
/** Player with the "theSeed" makes one move, with input
validation. Update global variables "currentRow" and
"currentCol". */ public static void playerMove(int theSeed)
{ boolean validInput = false; // for input validation do
{ if (theSeed == CROSS) {
System.out.print("Player 'X', enter your move (row[1-3]
column[1-3]): "); } else {
System.out.print("Player 'O', enter your move (row[1-3]
column[1-3]): "); } int row = in.nextInt() - 1; //
array index starts at 0 instead of 1 int col = in.nextInt() -
1; if (row >= 0 && row < ROWS && col >= 0 && col <
COLS && board[row][col] == EMPTY) { currntRow =
row; currentCol = col;
board[currntRow][currentCol] = theSeed; // update game-board
content validInput = true; // input okay, exit loop
} else { System.out.println( "This move at (" + (row +
1) + "," + (col + 1) + ") is not valid. Try
again..."); } } while (!validInput); // repeat until
input is valid } /** Update the "currentState" after the
player with "theSeed" has placed on (currentRow,
currentCol). */ public static void updateGame(int theSeed, int
currentRow, int currentCol) { if (hasWon(theSeed,
currentRow, currentCol)) { // check if winning move
currentState = (theSeed == CROSS) ? CROSS_WON :
NOUGHT_WON; } else if (isDraw()) { // check for draw
currentState = DRAW; } // Otherwise, no change to
currentState (still PLAYING). } /** Return true if it is a
draw (no more empty cell) */ // TODO: Shall declare draw if
no player can "possibly" win public static boolean isDraw()
{ for (int row = 0; row < ROWS; ++row) { for (int col
= 0; col < COLS; ++col) { if (board[row][col] ==
EMPTY) { return false; // an empty cell found, not
draw, exit } } } return true; // no empty
cell, it's a draw } /** Return true if the player with
"theSeed" has won after placing at (currentRow,
currentCol) */ public static boolean hasWon(int theSeed, int
currentRow, int currentCol) { return (board[currentRow][0]
== theSeed // 3-in-the-row &&
board[currentRow][1] == theSeed &&
board[currentRow][2] == theSeed ||
board[0][currentCol] == theSeed // 3-in-the-column
&& board[1][currentCol] == theSeed &&
board[2][currentCol] == theSeed || currentRow ==
currentCol // 3-in-the-diagonal &&
board[0][0] == theSeed && board[1][1] == theSeed
&& board[2][2] == theSeed || currentRow + currentCol
== 2 // 3-in-the-opposite-diagonal && board[0][2]
== theSeed && board[1][1] == theSeed
&& board[2][0] == theSeed); } /** Print the game board */
public static void printBoard() { for (int row = 0; row <
ROWS; ++row) { for (int col = 0; col < COLS; ++col) {
printCell(board[row][col]); // print each of the cells if
(col != COLS - 1) { System.out.print("|"); // print
vertical partition } } System.out.println();
if (row != ROWS - 1) { System.out.println( "-----------
"); // print horizontal partition } }
System.out.println(); } /** Print a cell with the specified
"content" */ public static void printCell(int content) {
switch (content) { case EMPTY: System.out.print(" ");
break; case NOUGHT: System.out.print( " O "); break;
case CROSS: System.out.print( " X "); break; } } }

More Related Content

Similar to Develop a game, with two gamers. Games rules made up themselfs. F.docx

I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfarchanaemporium
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfADITIEYEWEAR
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfaravlitraders2012
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfpoblettesedanoree498
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ projectUtkarsh Aggarwal
 
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdfNO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdffms12345
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquacareser
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquapariwar
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfinfo430661
 
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfimport tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfpreetajain
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfarmcomputers
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfinfo382133
 

Similar to Develop a game, with two gamers. Games rules made up themselfs. F.docx (14)

RandomGuessingGame
RandomGuessingGameRandomGuessingGame
RandomGuessingGame
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdf
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdfNO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfimport tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
 

More from ShiraPrater50

Read Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxRead Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxShiraPrater50
 
Read Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxRead Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxShiraPrater50
 
Read Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxRead Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxShiraPrater50
 
Read chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxRead chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxShiraPrater50
 
Read Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxRead Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxShiraPrater50
 
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxRead chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxShiraPrater50
 
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxRead Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxShiraPrater50
 
Read chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxRead chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxShiraPrater50
 
Read Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxRead Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxShiraPrater50
 
Read Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxRead Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxShiraPrater50
 
Journal of Public Affairs Education 515Teaching Grammar a.docx
 Journal of Public Affairs Education 515Teaching Grammar a.docx Journal of Public Affairs Education 515Teaching Grammar a.docx
Journal of Public Affairs Education 515Teaching Grammar a.docxShiraPrater50
 
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 Learner Guide TLIR5014 Manage suppliers TLIR.docx Learner Guide TLIR5014 Manage suppliers TLIR.docx
Learner Guide TLIR5014 Manage suppliers TLIR.docxShiraPrater50
 
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docxShiraPrater50
 
Leveled and Exclusionary Tracking English Learners Acce.docx
 Leveled and Exclusionary Tracking English Learners Acce.docx Leveled and Exclusionary Tracking English Learners Acce.docx
Leveled and Exclusionary Tracking English Learners Acce.docxShiraPrater50
 
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docxShiraPrater50
 
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 MBA 6941, Managing Project Teams 1 Course Learning Ou.docx MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
MBA 6941, Managing Project Teams 1 Course Learning Ou.docxShiraPrater50
 
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docxShiraPrater50
 
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docxShiraPrater50
 
MBA 5101, Strategic Management and Business Policy 1 .docx
 MBA 5101, Strategic Management and Business Policy 1 .docx MBA 5101, Strategic Management and Business Policy 1 .docx
MBA 5101, Strategic Management and Business Policy 1 .docxShiraPrater50
 
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 MAJOR WORLD RELIGIONSJudaismJudaism (began .docx MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
MAJOR WORLD RELIGIONSJudaismJudaism (began .docxShiraPrater50
 

More from ShiraPrater50 (20)

Read Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxRead Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docx
 
Read Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxRead Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docx
 
Read Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxRead Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docx
 
Read chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxRead chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docx
 
Read Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxRead Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docx
 
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxRead chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
 
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxRead Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
 
Read chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxRead chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docx
 
Read Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxRead Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docx
 
Read Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxRead Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docx
 
Journal of Public Affairs Education 515Teaching Grammar a.docx
 Journal of Public Affairs Education 515Teaching Grammar a.docx Journal of Public Affairs Education 515Teaching Grammar a.docx
Journal of Public Affairs Education 515Teaching Grammar a.docx
 
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 Learner Guide TLIR5014 Manage suppliers TLIR.docx Learner Guide TLIR5014 Manage suppliers TLIR.docx
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 
Leveled and Exclusionary Tracking English Learners Acce.docx
 Leveled and Exclusionary Tracking English Learners Acce.docx Leveled and Exclusionary Tracking English Learners Acce.docx
Leveled and Exclusionary Tracking English Learners Acce.docx
 
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 MBA 6941, Managing Project Teams 1 Course Learning Ou.docx MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 
MBA 5101, Strategic Management and Business Policy 1 .docx
 MBA 5101, Strategic Management and Business Policy 1 .docx MBA 5101, Strategic Management and Business Policy 1 .docx
MBA 5101, Strategic Management and Business Policy 1 .docx
 
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 MAJOR WORLD RELIGIONSJudaismJudaism (began .docx MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Develop a game, with two gamers. Games rules made up themselfs. F.docx

  • 1. Develop a game, with two gamers. Games rules made up themselfs. For example can take game “guess number”. Prepare at least 5 functions in program. Develop a game, with two gamers. Games rules made up themselfs. For example can take game “guess number”. Prepare at least 5 functions in program. Develop a game, with two gamers. Games rules made up themselfs. For example can take game “guess number”. Prepare at least 5 functions in program. with function description and java programming code (using eclipse) Solution import java.util.Scanner; /** * Tic-Tac-Toe: Two-player console, non-graphics, non-OO version. * All variables/methods are declared as static (belong to the class) * in the non-OO version. */ public class TTTConsoleNonOO2P { // Name-constants to represent the seeds and cell contents public static final int EMPTY = 0; public static final int CROSS = 1; public static final int NOUGHT = 2; // Name- constants to represent the various states of the game public static final int PLAYING = 0; public static final int DRAW = 1; public static final int CROSS_WON = 2; public static final int NOUGHT_WON = 3; // The game board and the game status public static final int ROWS = 3, COLS = 3; // number of rows and columns public static int[][] board = new
  • 2. int[ROWS][COLS]; // game board in 2D array // containing (EMPTY, CROSS, NOUGHT) public static int currentState; // the current state of the game // (PLAYING, DRAW, CROSS_WON, NOUGHT_WON) public static int currentPlayer; // the current player (CROSS or NOUGHT) public static int currntRow, currentCol; // current seed's row and column public static Scanner in = new Scanner(System.in); // the input Scanner /** The entry main method (the program starts here) */ public static void main(String[] args) { // Initialize the game-board and current status initGame(); // Play the game once do { playerMove(currentPlayer); // update currentRow and currentCol updateGame(currentPlayer, currntRow, currentCol); // update currentState printBoard(); // Print message if game-over if (currentState == CROSS_WON) { System.out.println( "'X' won! Bye!"); } else if (currentState == NOUGHT_WON) { System.out.println("'O' won! Bye!"); } else if (currentState == DRAW) { System.out.println("It's a Draw! Bye!"); } // Switch player currentPlayer = (currentPlayer == CROSS) ? NOUGHT : CROSS; } while (currentState == PLAYING); // repeat if not game-over } /** Initialize the game-board contents and the current states */ public static void initGame() { for (int row = 0; row < ROWS; ++row) { for (int col = 0; col
  • 3. < COLS; ++col) { board[row][col] = EMPTY; // all cells empty } } currentState = PLAYING; // ready to play currentPlayer = CROSS; // cross plays first } /** Player with the "theSeed" makes one move, with input validation. Update global variables "currentRow" and "currentCol". */ public static void playerMove(int theSeed) { boolean validInput = false; // for input validation do { if (theSeed == CROSS) { System.out.print("Player 'X', enter your move (row[1-3] column[1-3]): "); } else { System.out.print("Player 'O', enter your move (row[1-3] column[1-3]): "); } int row = in.nextInt() - 1; // array index starts at 0 instead of 1 int col = in.nextInt() - 1; if (row >= 0 && row < ROWS && col >= 0 && col < COLS && board[row][col] == EMPTY) { currntRow = row; currentCol = col; board[currntRow][currentCol] = theSeed; // update game-board content validInput = true; // input okay, exit loop } else { System.out.println( "This move at (" + (row + 1) + "," + (col + 1) + ") is not valid. Try again..."); } } while (!validInput); // repeat until input is valid } /** Update the "currentState" after the player with "theSeed" has placed on (currentRow, currentCol). */ public static void updateGame(int theSeed, int currentRow, int currentCol) { if (hasWon(theSeed,
  • 4. currentRow, currentCol)) { // check if winning move currentState = (theSeed == CROSS) ? CROSS_WON : NOUGHT_WON; } else if (isDraw()) { // check for draw currentState = DRAW; } // Otherwise, no change to currentState (still PLAYING). } /** Return true if it is a draw (no more empty cell) */ // TODO: Shall declare draw if no player can "possibly" win public static boolean isDraw() { for (int row = 0; row < ROWS; ++row) { for (int col = 0; col < COLS; ++col) { if (board[row][col] == EMPTY) { return false; // an empty cell found, not draw, exit } } } return true; // no empty cell, it's a draw } /** Return true if the player with "theSeed" has won after placing at (currentRow, currentCol) */ public static boolean hasWon(int theSeed, int currentRow, int currentCol) { return (board[currentRow][0] == theSeed // 3-in-the-row && board[currentRow][1] == theSeed && board[currentRow][2] == theSeed || board[0][currentCol] == theSeed // 3-in-the-column && board[1][currentCol] == theSeed && board[2][currentCol] == theSeed || currentRow == currentCol // 3-in-the-diagonal && board[0][0] == theSeed && board[1][1] == theSeed && board[2][2] == theSeed || currentRow + currentCol == 2 // 3-in-the-opposite-diagonal && board[0][2]
  • 5. == theSeed && board[1][1] == theSeed && board[2][0] == theSeed); } /** Print the game board */ public static void printBoard() { for (int row = 0; row < ROWS; ++row) { for (int col = 0; col < COLS; ++col) { printCell(board[row][col]); // print each of the cells if (col != COLS - 1) { System.out.print("|"); // print vertical partition } } System.out.println(); if (row != ROWS - 1) { System.out.println( "----------- "); // print horizontal partition } } System.out.println(); } /** Print a cell with the specified "content" */ public static void printCell(int content) { switch (content) { case EMPTY: System.out.print(" "); break; case NOUGHT: System.out.print( " O "); break; case CROSS: System.out.print( " X "); break; } } }