hi, i have a hw for CS 141 class, but i have no idea how to start writing code.
ID: 3544768 • Letter: H
Question
hi, i have a hw for CS 141 class, but i have no idea how to start writing code.
it is text-based Memory game.
i will use a two-dimensional array to represent the grid for the game. The dimension of the array is: 4x4.
The symbols used in the game are: ?, +, -, *, !, /, #, %
The rules are the standard rules of memory: 16 cards are arranged, upside down, and there are 2 cards of each type. The played flips over two cards every turn. If they match they remain turned, otherwise they are turned upside down again. The game ends when the player uncovers all the cards.
I will implement a simple interface from which the game can be started, and will keep track of the numbers of moves, reporting them at the end.
i have at least the following entities represented as classes:
Main class - where main resides, from which the program is launche
User Interface: the entity in charge of the interactive part of the program: displaying information and obtaining input from the user
Game Engine: the entity that represents an intance of the game. Keeps track the current state of the game, statistics like the number of moves, etc.
Grid: represents the grid. It should internally hold the two-dimensional array used to represent the card layout
Abstract Card: the abstract notion of a card. This class should know whether a class is flipped or not
Actual Card: each type of card should be represented as a class
no java swing class ,and no awt
just using import java.util.io.*
please help me
Explanation / Answer
import java.io.*;
import java.util.*;
class Main
{
public static void main()
{
System.out.println("The numbers are mapped to the squares in the following way:");
for(int i=1;i<=16;i++)
{
System.out.print(i+" ");
if(i%4==0)
System.out.println();
}
}
}
class UserInterface
{
void display(Card grid[][])
{
for(int i=0;i<3;i++)
{
System.out.println();
for(int j=0;j<4;j++)
{
if(grid[i][j].flipped==true)
System.out.print(grid[i][j].e+" ");
else
System.out.print("x ");
}
}
}
}
class GameEngine
{
Card Grid[][];
public GameEngine()
{
Grid=new Card[4][4];
char a={'?', '+', '-', '*', '!', '/', '#', '%','?', '+', '-', '*', '!', '/', '#', '%'};
}
}
abstract class AbsCard
{
boolean flipped;
}
class Card extends AbsCard
{
char e;
public Card(char e)
{
this.e=e;
this.flipped=false;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.